package com.java.synchronized_.question.static_nostatic_method;

/**
 * 都有锁，锁对象不同，调用对象不同
 */
public class QuestionB {
    static class Inner {
        private static void func() {
            System.out.println(Thread.currentThread().getName() + "开始");
            try {
                Thread.sleep(2000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println(Thread.currentThread().getName() + "结束");
        }
        
        public static synchronized void syncFunc1() {
            func();
        }
        
        public synchronized void syncFunc2() {
            func();
        }
    }
    
    public static void main(String[] args) {
        Inner inner1 = new Inner();
        Inner inner2 = new Inner();
        
        new Thread(() -> {
            inner1.syncFunc1();
        }).start();
        
        new Thread(() -> {
            inner2.syncFunc2();
        }).start();
    }
    
    /**
     * 输出结果如下
     * Thread-0开始
     * Thread-1开始
     * Thread-1结束
     * Thread-0结束
     */
}
